<template>
	<view class="container">
		
		<view class="tui-rate-box">
			<view class="tui-goods-item">
				<image :src="goodsLogo" class="tui-goods-img"></image>
				<view class="tui-goods-center">
					<view class="tui-goods-name">{{goodsName}}</view>
					<view class="tui-goods-attr">{{goodsFormat}}</view>
				</view>
			</view>
		</view>
		
		<view class="tui-rate-box">
			<view class="tui-title">综合评价</view>
			<tui-rate :current="index" :hollow="true" @change="change" normal="#ccc" active="#ff7900"></tui-rate>
		</view>
		
		<view class="tui-rate-textarea">
			<view class="tui-title tui-top40">发表你的评论</view>
			<view class="tui-cells-textarea">
				<textarea v-model="remark" class="tui-textarea tui-textarea-my" name="desc" placeholder="你的满意是我们最大的努力." maxlength="200"
				 placeholder-class="tui-phcolor-color" />
				<!-- <view class="tui-textarea-counter">0/200</view> -->
			</view>
		</view>
		
		<view class="tui-rate-btn" @click="postRankData">
			<button class="tui-btn tui-btn-block tui-warning" hover-class="tui-warning-hover">提交你的评价</button>
		</view>
	</view>
</template>

<script>
	import tuiRate from "@/components/thorui/tui-rate/tui-rate";
	import tuiButton from "@/components/thorui/tui-button/tui-button";
	export default {
		components:{
			tuiRate,
			tuiButton,
		},
		data() {
			return {
				loadding: false,
				show: false,
				current: 0,
				
				index: 5,
				remark: '',
				
				infoId: 0,
				goodsId: 0,
				goodsName: '',
				goodsLogo: '',
				goodsFormat: '',
			}
		},
		methods: {
			change: function(e) {
				this.index = e.index;
				this.current = e.index
			},
			
			//得到评价的内容
			getRankInfo: function() {
				uni.request({
					url: this.$apiUrl + '/api/my-order/rank-info',
					header: {
						'userId': uni.getStorageSync('userId'),
						'userToken': uni.getStorageSync('userToken'),
            'shopId': uni.getStorageSync('shopId')
					},
					data: {
						info_id: this.infoId,
					},
					success: (res) => {
						let resData = res.data['data'];
						this.goodsName = resData.goods_name;
						this.goodsFormat = resData.goods_format;
						this.goodsLogo = resData.goods_logo;
						this.goodsId = resData.goods_id;
					}
				});
			},
			
			//得到评价的内容
			postRankData: function() {
				uni.request({
					url: this.$apiUrl + '/api/my-goods/rank-add',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'userId': uni.getStorageSync('userId'),
						'userToken': uni.getStorageSync('userToken'),
            'shopId': uni.getStorageSync('shopId')
					},
					data: {
						info_id: this.infoId,
						goods_id: this.goodsId,
						score: this.index,
						remark: this.remark,
					},
					success: (res) => {
						let resMsg = res.data['msg'];
						this.tui.toast(resMsg);
						uni.navigateTo({
							url: '/pages/my-order/for-rank'
						});
					}
				});
			},	
			
		},
		
		onLoad: function(options) {
			this.infoId = options.info_id || 0;
			this.getRankInfo();
		},
	}
</script>

<style>
	@import '../../static/style/thorui.css';
	
	.container {
		padding: 20upx 0 120upx 0;
		box-sizing: border-box;
	}

	.header {
		padding: 80upx 90upx 60upx 90upx;
		box-sizing: border-box;
	}

	.title {
		font-size: 34upx;
		color: #333;
		font-weight: 500;
	}

	.sub-title {
		font-size: 24upx;
		color: #7a7a7a;
		padding-top: 18upx;
	}

	.tui-rate-box {
		padding: 20rpx;
		box-sizing: border-box;
		margin-bottom: 30rpx;
		background: #fff;
		font-size: 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.tui-title {
		font-size: 30rpx;
	}
	
	.tui-rate-btn{
		width: 90%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 0 auto;
	}
	
	.tui-rate-textarea{
		padding: 20rpx;
		box-sizing: border-box;
		margin-bottom: 30rpx;
		background: #fff;
		font-size: 30rpx;
		display: row;
	}
	
	.tui-top40{
		padding: 20rpx 0;
	}
	
	.tui-btn{
		margin-bottom: 26upx;
		margin-right: 20upx;
	}
	
	.flex-box {
		width: 100%;
	}
	
	
	.tui-order-item {
		margin-top: 20rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}
	
	.tui-goods-title {
		width: 100%;
		font-size: 28rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	
	.tui-order-status {
		color: #888;
		font-size: 26rpx;
	}
	
	.tui-goods-item {
		width: 100%;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
	}
	
	.tui-goods-img {
		width: 180rpx;
		height: 180rpx;
		display: block;
		flex-shrink: 0;
	}
	
	.tui-goods-center {
		flex: 1;
		padding: 20rpx 8rpx;
		box-sizing: border-box;
	}
	
	.tui-goods-name {
		max-width: 310rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		font-size: 26rpx;
		line-height: 32rpx;
	}
	
	.tui-goods-attr {
		font-size: 22rpx;
		color: #888888;
		line-height: 32rpx;
		padding-top: 20rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}
	
	.tui-price-right {
		text-align: right;
		font-size: 24rpx;
		color: #888888;
		line-height: 30rpx;
		padding-top: 20rpx;
	}
	
	.tui-color-red {
		color: #E41F19;
		padding-right: 30rpx;
	}
	
	.tui-goods-price {
		width: 100%;
		display: flex;
		align-items: flex-end;
		justify-content: flex-end;
		font-size: 24rpx;
	}
	
	.tui-size-24 {
		font-size: 24rpx;
		line-height: 24rpx;
	}
	
	.tui-price-large {
		font-size: 32rpx;
		line-height: 30rpx;
		font-weight: 500;
	}
	
	.tui-order-btn {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		background: #fff;
		padding: 10rpx 30rpx 20rpx;
		box-sizing: border-box;
	}
	
	.tui-cells-textarea{
		border: 2prx solid #333;
	}
	.tui-textarea{
		border: 2prx solid #333;
	}
	.uni-textarea-textarea{
		border: 2prx solid #333;
	}
	
	.tui-textarea-my{
		border:1px solid #ddd;border-radius:5px;padding:10px;width: 94%;
	}
	
</style>